# GDIR define
GDIR=../../..
GIMDIR = $(GDIR)

# MACIPATH define
MACIPATH=$(GDIR)/MaCI

GRIDPATH=$(GDIR)/LnMlib/src/map
#SMPATH=$(GDIR)/LnMlib/src/scanmatch
MCLPATH=$(GDIR)/LnMlib/src/mcl


#CPPSM = $(SMPATH)/CAHistogramECorrelationScanMatch.cpp
#CPP_MCL = $(MCLPATH)/CTopoScanOccuMCL.cpp $(MCLPATH)/CParticleFilter.cpp

CPPIMAGEGUI = $(GDIR)/glutImageGUI/glutImageGUI.cpp
RGBDATA = $(GDIR)/glutgui/RGBImage.cpp

# External includes

#include $(GDIR)/grid/Makefile.occu #OCCU_SRC_CPP
LNMDIR= $(GDIR)/LnMlib/src

include $(LNMDIR)/map/Makefile.occu #OCCU_SRC_CPP

include $(GDIR)/GIMI/Makefile.gimi
include $(MACIPATH)/interfaces/MaCI-interfaces.Makefile
#include $(LNMDIR)/BetB_dt/Makefile.bbdt


# All sources needed by the SLAM
##CPPLOC = $(CPPSM) $(CPPIMAGEGUI) $(RGBDATA) $(OCCU_SRC_CPP) $(CPP_MCL) $(BBDT_SRC_CPP)
CPPMAP = $(CPPIMAGEGUI) $(RGBDATA) $(OCCU_SRC_CPP) 


# params
CC=gcc
CXX=g++
EXTRADEFS=-DLINUX_OS -DGIMI_NO_DATATYPE_INCLUDES $(CE)
#-DUSE_MACI_OCCUMAPPER_DEBUG
#-DUSE_IMAGEGUI
MACIPATH=$(GDIR)/MaCI
UTILSPATH=$(GDIR)/utils
BUSPATH=$(MACIPATH)/bus
DRIVERPATH=$(MACIPATH)/drivers
MACIINTERFACEPATH=$(MACIPATH)/interfaces

INCLUDES=$(INCGIMI) \
	 $(MACI_INCLUDE_PATHS) \
	 $(OCCU_INCLUDE) \
	 $(BBDT_INCLUDE) \
	 -I$(GRIDPATH) \
	 -I$(SMPATH) \
	 -I$(GDIR)/glutImageGUI \
	 -I$(GDIR)/glutgui \
	 -I$(GDIR)/ImageUtils/JPEGDecoder \
	 -I$(GDIR)/ImageUtils/PNGDecoder \
         -I$(GDIR)/ImageUtils/PNGEncoder \
         -I$(GDIR)/ImageUtils/JPEGEncoder \
	 -I$(GDIR)/ImageUtils/conversions \
	 -I$(MCLPATH)
WFLAGSC=
WFLAGSCPP=
WFLAGSDCPP=
CFLAGS=-O0 -g3 $(WFLAGSC) $(INCLUDES) $(EXTRADEFS)
CPPFLAGS=-O0 -g3 $(WFLAGSCPP) $(INCLUDES) $(EXTRADEFS)
DCPPFLAGS=-O0 -g3 $(WFLAGSDCPP) $(INCLUDES) $(EXTRADEFS)
LD=g++
LDFLAGS=
LIBS=-lrt -lpthread $(LIBSGIMI) -lGL -lGLU -lglut \
     $(MACI_INTERFACE_MAP_EXT_LIBS) \
     $(MACI_INTERFACE_IMAGE_EXT_LIBS)

SRCSC=$(CGIMI) $(MACI_INTERFACE_MAP_EXT_C) $(MACI_INTERFACE_IMAGE_EXT_C)
SRCSCPP=$(CPPGIMI) $(CPPMAP)
MACISRCSCPP=$(MACI_EXT_SRC_CPP) \
	    $(MACI_BASE_SRC_CPP) \
	    $(MACI_INTERFACE_POSITION_COMMON_CPP) \
	    $(MACI_INTERFACE_POSITIONSERVER_CPP) \
	    $(MACI_INTERFACE_POSITIONCLIENT_CPP) \
	    $(MACI_INTERFACE_RANGING_COMMON_CPP) \
	    $(MACI_INTERFACE_RANGINGSERVER_CPP) \
	    $(MACI_INTERFACE_RANGINGCLIENT_CPP) \
	    $(MACI_INTERFACE_MAP_COMMON_CPP) \
	    $(MACI_INTERFACE_MAPSERVER_CPP) \
	    $(MACI_INTERFACE_MAP_EXT_CPP) \
	    $(MACI_INTERFACE_IMAGE_COMMON_CPP) \
	    $(MACI_INTERFACE_IMAGESERVER_CPP) \
	    $(MACI_INTERFACE_IMAGE_EXT_CPP) \
	    $(MACI_INTERFACE_ENVIRONMENTMEASUREMENT_EXT_CPP)
VPATH=

# Construct final lists of CPP and C objects
OBJSC=$(SRCSC:.c=.o)
OBJSCPP=$(SRCSCPP:.cpp=.opp)
MACIOBJSCPP=$(MACISRCSCPP:.cpp=.opp)

OBJ_LOC=$(CPPLOC:.cpp=.opp)

# Define COMPILE and LINK commands
COMPILEC=$(CC) $(CFLAGS) -c
COMPILECPP=$(CXX) $(CPPFLAGS) -c
COMPILEDCPP=$(CXX) $(DCPPFLAGS) -c
LINK=$(LD) $(LDFLAGS) 

.PHONY: all

# Define targets
#MaCI_OccuMapper 
TARGETS=PositionRanging_Logger PositionRangingx2_Logger

# All rule compiles all per default
all:	$(TARGETS)

###############################################
###############################################
MaCI_OccuMapper: $(OBJSC) $(OBJSCPP) $(MACIOBJSCPP) \
		  MaCI_OccuMapper.opp
	@$(LINK) -o $@ $^ $(LIBS)
	@echo "      [LD] $@"
	
PositionRanging_Logger: $(OBJSC) $(OBJSCPP) $(MACIOBJSCPP) \
		  PositionRanging_Logger.opp
	@$(LINK) -o $@ $^ $(LIBS)
	@echo "      [LD] $@"
PositionRangingx2_Logger: $(OBJSC) $(OBJSCPP) $(MACIOBJSCPP) \
	PositionRangingx2_Logger.opp
	@$(LINK) -o $@ $^ $(LIBS)
	@echo "      [LD] $@"
###############################################

###############################################
###############################################
.PHONY: clean maci-clean maciclean real-clean realclean
local-clean clean:
	@rm -f *.o *.opp *~ *.log $(TARGETS)
	@echo "     [LOCAL-CLEAN]"

maci-clean maciclean: clean
	rm -f $(MACIOBJSCPP) $(OBJ_LOC)
	@echo "     [MACI-CLEAN]"

real-clean realclean: maciclean
	rm -f $(OBJSC) $(OBJSCPP)
	@echo "     [REAL-CLEAN]"

########### Compile rules ####################
# Compile rule for all .o (.c) file
%.o:	%.c
	@$(COMPILEC) -o $@ $<
	@echo "      [CC] $<"

# Compile rule for all .opp (.cpp) files
%.opp:	%.cpp
	@$(COMPILECPP) -o $@ $<
	@echo "      [CXX] $<"

# Compile rule for all .dopp (dirty .cpp) files
%.dopp:	%.cpp
	@$(COMPILEDCPP) -o $@ $<
	@echo "      [DIRTY-CXX] $<"

##############################################
